<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>节点列表</title>
<link rel="stylesheet" type="text/css" href="${ctx }/css/main.css" />
<script type="text/javascript" src="${ctx }/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="${ctx }/widget/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx }/js/common.js"></script>
<script type="text/javascript">
	$(function() {

		//按纽样式
		$(".button1,.button2").hover(function() {
			$(this).addClass("button1Over");
			$(".button1Left", $(this)).show();
			$(".button1Right", $(this)).show();
		}, function() {
			$(this).removeClass("button1Over");
			$(".button1Left", $(this)).hide();
			$(".button1Right", $(this)).hide();
		});

		//全选,反选
		$("#checkAll").click(function() {
			$(".checkList").attr("checked", !!$("#checkAll").attr("checked"));
		});

		//添加节点
		$("#addNode").click(
				function() {
					overrideSelectedTabForSubPage('addNode', '新增节点',
							'admin/node.do?action=toAddNode');
				});

		//删除节点(顶部按纽栏)
		$("#deleteNode")
				.click(
						function() {
							var checkListArr = "";

							if ($(".checkList:checked").length < 1) {
								alert("请选择要删除的选项");
								return false;
							}
							if (!confirm("您确定要删除吗?")) {
								return false;
							}

							//检查通过，进行删除操作
							$(".checkList:checked")
									.each(
											function() {
												checkListArr = checkListArr == "" ? checkListArr
														+ $(this).val()
														: checkListArr + ","
																+ $(this).val();
											});

							$.ajax({
								type : "POST",
								url : "node.do?action=deleteNode&randomNum="
										+ new Date().getTime() + Math.random(),
								cache : false,
								data : "id=" + checkListArr,
								dataType : "text",
								success : function(data) {
									alert(data);
									overrideSelectedTabForSubPage('listNode',
											'节点管理',
											'admin/node.do?action=listNode');
								}
							});
						});

		//修改节点(顶部按纽栏)
		$("#updateNode")
				.click(
						function() {
							var checkList = $(".checkList:checked"), checkListLength = checkList.length, checkListValue = checkList
									.val();
							if (checkListLength < 1) {
								alert("请选择要修改的选项");
								return false;
							} else if (checkListLength > 1) {
								alert("对不起，只能选择一项进行修改");
								return false;
							}
							overrideSelectedTabForSubPage('updateNode', '修改节点',
									'admin/node.do?action=toUpdateNode&id='
											+ checkListValue);

						});

		//搜索节点
		$("#toSearch").click(function() {
			var formToExport = document.getElementById("queryForm");

			var formAction = "node.do?action=searchNode";

			formAction += getFormActionCriteria();

			formToExport.action = formAction;

			formToExport.submit();
			$("#searchTable").show();
		})

		//导出节点
		$("#toExportNodeList").click(function() {
			var formToExport = document.getElementById("queryForm");

			var formAction = "node.do?action=exportNodeList";

			formAction += getFormActionCriteria();

			formToExport.action = formAction;

			formToExport.submit();
			$("#searchTable").show();
		})

		//获取搜索条件

		function getFormActionCriteria() {
			var formAction = "";
			formAction += formAction += "&name=" + $("#name").val();
			formAction += "&parentId=" + $("#parentId").val();
			formAction += "&isLeaf=" + $("#isLeaf").val();
			formAction += "&fullPathName=" + $("#fullPathName").val();
			formAction += "&type=" + $("#type").val();
			formAction += "&fullPathId=" + $("#fullPathId").val();
			formAction += "&link=" + $("#link").val();
			formAction += "&level=" + $("#level").val();

			return formAction;
		}

		//重置
		$("#reset").click(
				function() {
					overrideSelectedTabForSubPage('listNode', '节点管理',
							'admin/node.do?action=listNode');
				})

		//展开搜索栏
		$("#expandSearchTable").click(function() {
			$("#searchTable").show();
			$(this).hide();
			$("#foldSearchTable").show();
		});

		//收缩搜索栏
		$("#foldSearchTable").click(function() {
			$("#searchTable").hide();
			$(this).hide();
			$("#expandSearchTable").show();

		});

		//更新节点(表格列表操作)
		$(".update").click(
				function() {
					overrideSelectedTabForSubPage('updateNode', '修改节点',
							'admin/node.do?action=toUpdateNode&id='
									+ $(this).attr("value"));
				});

		//删除节点(表格列表操作)
		$(".delete").click(
				function() {

					if (!confirm("您确定要删除吗?")) {
						return false;
					}

					$.ajax({
						type : "POST",
						url : "node.do?action=deleteNode&randomNum="
								+ new Date().getTime() + Math.random(),
						cache : false,
						data : "id=" + $(this).attr("value"),
						dataType : "text",
						success : function(data) {
							alert(data);
							overrideSelectedTabForSubPage('listNode', '节点管理',
									'admin/node.do?action=listNode');
						}
					});
				});

		//查看节点
		$(".view").click(
				function() {
					overrideSelectedTabForSubPage('viewNode', '查看节点',
							'admin/node.do?action=viewNode&id='
									+ $(this).attr("value"));
				});

	});
</script>
</head>
<body>
	<div class="functionList">

		<div class="button1" id="addNode">
			<div class="button1Left"></div>
			新增
			<div class="button1Right"></div>
		</div>

		<div class="button1" id="updateNode">
			<div class="button1Left"></div>
			修改
			<div class="button1Right"></div>
		</div>

		<div class="button1" id="deleteNode">
			<div class="button1Left"></div>
			删除
			<div class="button1Right"></div>
		</div>

		<div class="button2" id="expandSearchTable" style="display: none;">
			<div class="button1Left"></div>
			展开搜索
			<div class="button1Right"></div>
		</div>

	</div>
	<%-- <form action="${ctx }/admin/node.do?action=searchNode" name="queryForm"
		id="queryForm" method="post">
		<table width="100%" border="1" class="formTable" id="searchTable">
			<tr>
				<td class="fieldName" width="10%">name:</td>
				<td class="fieldForm" width="40%"><input type="text"
					name="name" id="name" value="${bean.name  }" /></td>
				<td class="fieldName" width="10%">parentId:</td>
				<td class="fieldForm" width="40%"><input type="text"
					name="parentId" id="parentId" value="${bean.parentId  }" /></td>
			</tr>
			<tr>
				<td class="fieldName" width="10%">isLeaf:</td>
				<td class="fieldForm" width="40%"><input type="text"
					name="isLeaf" id="isLeaf" value="${bean.isLeaf  }" /></td>
				<td class="fieldName" width="10%">fullPathName:</td>
				<td class="fieldForm" width="40%"><input type="text"
					name="fullPathName" id="fullPathName"
					value="${bean.fullPathName  }" /></td>
			</tr>
			<tr>
				<td class="fieldName" width="10%">type:</td>
				<td class="fieldForm" width="40%"><input type="text"
					name="type" id="type" value="${bean.type  }" /></td>
				<td class="fieldName" width="10%">fullPathId:</td>
				<td class="fieldForm" width="40%"><input type="text"
					name="fullPathId" id="fullPathId" value="${bean.fullPathId  }" /></td>
			</tr>
			<tr>
				<td class="fieldName" width="10%">link:</td>
				<td class="fieldForm" width="40%"><input type="text"
					name="link" id="link" value="${bean.link  }" /></td>
				<td class="fieldName" width="10%">level:</td>
				<td class="fieldForm" width="40%"><input type="text"
					name="level" id="level" value="${bean.level  }" /></td>
			</tr>
			<tr>
				<td colspan="4" align="center"><input type="submit" value="搜索"
					id="toSearch" name="toSearch" class="submitButton" /> <input
					type="button" value="导出" id="toExportNodeList"
					name="toExportNodeList" class="submitButton" /> <input
					type="reset" id="reset" name="reset" value="重置"
					class="submitButton" /> <input type="reset" id="foldSearchTable"
					value="隐藏搜索" class="submitButton" /></td>
				</td>
			</tr>
		</table>
	</form> --%>
	<table width="100%" id="mytab" border="1" class="t1">
		<thead>
			<tr>
				<th><input type="checkbox" id="checkAll" /></th>
				<th>节点名称</th>
				<th>节点类型</th>
				<th>操作</th>
			</tr>
		</thead>
		<c:if test="${empty nodeList}">
			<tr>
				<td colspan="13">对不起，暂时没有数据</td>
			</tr>

		</c:if>
		<c:forEach items="${nodeList }" var="nodeList" varStatus="vs">
			<tr <c:if test="${vs.index %2==1 }">
					class="a1"
				</c:if>>
				<td><input type="checkbox" class="checkList" name="checkList"
					value="${nodeList.id }" /></td>
				<td><c:if test="${nodeList.level ==1 }">
								≡&nbsp;${nodeList.name }
								</c:if> <c:if test="${nodeList.level ==2 }">
								&nbsp;&nbsp;&nbsp;└&nbsp;${nodeList.name }
								</c:if> <c:if test="${nodeList.level ==3 }">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└&nbsp;${nodeList.name }
								</c:if> <c:if test="${nodeList.level ==4 }">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└&nbsp;${nodeList.name }
								</c:if> <c:if test="${nodeList.level ==5 }">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└&nbsp;${nodeList.name }
								</c:if></td>
				<td><c:if test="${nodeList.type =='text'}">
				文本节点
				</c:if> <c:if test="${nodeList.type =='link'}">
				链接节点
				</c:if></td>
				<td><span class="update operationButton"
					value="${nodeList.id }">修改</span> <span class="operationButton">|</span>
					<span class="delete operationButton" value="${nodeList.id }">删除</span><span
					class="operationButton">|</span> <span class="view operationButton"
					value="${nodeList.id }">查看</span></td>
			</tr>
		</c:forEach>
	</table>
</body>
</html>
